package my_hash_module

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ComputeHmacSha256(message string, secret string) string {
	h := hmac.New(sha256.New, []byte(secret)) // hmac with app secret
	h.Write([]byte(message)) // write sign pattern
	return base64.URLEncoding.EncodeToString(h.Sum(nil)) // base64url toString
}

func ComputeHmacSha256Service(context *gin.Context){
	message := context.PostForm("message")
	secret := context.PostForm("secret")
	sign := ComputeHmacSha256(message, secret)

	context.JSON(http.StatusOK, sign)
}
